<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="__STATIC__/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script type="text/javascript" src="__STATIC__/js/jquery2.0.js"></script>
    <script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">基础配置</a>
        <a>
          <cite>自定义菜单管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="x-body">
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="xadmin.open('添加活动','./menuAdd?menu_id={$menu_id}')"><i class="layui-icon"></i>添加</button>
        <button class="layui-btn layui-btn-danger" onclick="shengcheng()"><i class="layui-icon"></i>生成菜单</button>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>编号</th>
            <th>ID</th>
            <th>菜单名称</th>
            <th>菜单类型</th>
            <th>菜单等级</th>
            <th>排序</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $data as $key=>$vo}
        <tr>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$key+1}</td>
            <td>{$vo.id}</td>
            <td>{$vo.menu_name}</td>
            <td>
                {if $vo.menu_type eq 'click'}
                    <span class="layui-btn layui-btn-xs">点击事件</span>
                {else/}
                    <span class="layui-btn layui-btn-xs layui-btn-danger">链接</span>
                {/if}
            </td>
            <td>
                {if $vo.menu_id eq 0}
                    <span class="layui-btn layui-btn-xs">一级菜单</span>
                {else/}
                    <span class="layui-btn layui-btn-xs layui-btn-danger">二级菜单</span>
                {/if}
            </td>
            <td>{$vo.menu_sort}</td>
            <td class="td-manage">
                <a title="编辑"  onclick="xadmin.open('编辑','{:url("wxpage/menuEdit")}?id='+{$vo.id})" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                {if $vo.menu_id eq 0}
                    <a title="二级菜单"  onclick="xadmin.open('二级分类','{:url("wxpage/menu")}?id='+{$vo.id})" href="javascript:;">
                        <i class="layui-icon">&#xe65b;</i>
                    </a>
                {else/}
                {/if}
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
    <div class="page">
        <div>
            {$data|raw}
        </div>
    </div>
</div>
<script>
    layui.use(['laydate','table'], function(){
        var laydate = layui.laydate
            ,table = layui.table;
    });
    function shengcheng (argument) {
        layer.confirm('确认要发布吗？',function(index){
            $.post('{:url("wechat/pub_menu")}',function(res){
                if(res.code=='success'){
                    layer.alert("发布成功！", {icon: 6}, function () {
                        window.location.reload();
                    });
                }else{
                    layer.msg("发布失败！",{icon:1,time:3000});
                }
            });
        });
    }
    function delAll (argument) {
        var data = tableCheck.getData();
        layer.confirm('确认要删除吗？',function(index){
            $.post('{:url("wxpage/menuDel")}',{'data':data},function(res){
                if(res.msg=='success'){
                    layer.alert("删除成功", {icon: 6}, function () {
                        window.location.reload();
                    });
                }else{
                    layer.msg("删除失败",{icon:1,time:3000});
                }
            });
        });
    }

    tableCheck = {
        init:function  () {
            $(".layui-form-checkbox").click(function(event) {
                if($(this).hasClass('layui-form-checked')){
                    $(this).removeClass('layui-form-checked');
                    if($(this).hasClass('header')){
                        $(".layui-form-checkbox").removeClass('layui-form-checked');
                    }
                }else{
                    $(this).addClass('layui-form-checked');
                    if($(this).hasClass('header')){
                        $(".layui-form-checkbox").addClass('layui-form-checked');
                    }
                }

            });
        },
        getData:function  () {
            var obj = $(".layui-form-checked").not('.header');
            var arr=[];
            obj.each(function(index, el) {
                arr.push(obj.eq(index).attr('data-id'));
            });
            return arr;
        }
    };
    //开启表格多选
    tableCheck.init();
</script>
</body>

</html>